package breeze.pixel.weather.weather_forecast.view;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import breeze.pixel.weather.BaseView;
import breeze.pixel.weather.R;
import breeze.pixel.weather.adapter.weather.DailyWeatherAdapter;
import breeze.pixel.weather.apps_util.utils.AppToolUtil;
import breeze.pixel.weather.apps_util.views.mtextview.MTextView;

public class ShowForecastView extends BaseView {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forecast);
        init();
    }

    public static DailyWeatherAdapter.DailyBean data;
    @Override
    public void init() {
        MTextView mf2_wet = find(R.id.f2_wet);
        MTextView mf2_down_water = find(R.id.f2_down_water);
        MTextView mf2_air_press = find(R.id.f2_air_press);
        MTextView mf2_ziwaixian = find(R.id.f2_ziwaixian);
        MTextView mf2_can_see = find(R.id.f2_can_see);
        MTextView mf_city_time = find(R.id.f_city_time);
        MTextView mf_city_name = find(R.id.f_city_name);
        MTextView mf_sun_rise = find(R.id.f_sun_rise);
        MTextView mf_sun_down = find(R.id.f_sun_down);
        ImageView mf_weather_icon = find(R.id.f_weather_icon);
        MTextView mf_weather_text = find(R.id.f_weather_text);
        MTextView mf_moon_rise = find(R.id.f_moon_rise);
        MTextView mf_moon_down = find(R.id.f_moon_down);
        ImageView mf_weather_icon_n = find(R.id.f_weather_icon_n);
        MTextView mf_weather_text_n = find(R.id.f_weather_text_n);
        MTextView mf_wind = find(R.id.f_wind);
        MTextView mf_tem = find(R.id.f_tem);
        if (data != null) {
            mf_city_name.setText(getIntent().getStringExtra("cityName"));
            mf_city_time.setText(data.getFxDate());
            mf_sun_rise.setText(String.format("%s%s", getString(R.string.sun_rise), data.getSunrise()));
            mf_sun_down.setText(String.format("%s%s", getString(R.string.sun_down), data.getSunset()));
            mf_moon_rise.setText(String.format("%s%s", getString(R.string.moon_rise), data.getMoonRise()));
            mf_moon_down.setText(String.format("%s%s", getString(R.string.moon_down), data.getMoonSet()));
            mf_weather_icon.setImageBitmap(AppToolUtil.getweatherIcon(this, data.getIconDay()));
            mf_weather_icon_n.setImageBitmap(AppToolUtil.getweatherIcon(this, data.getIconNight()));
            mf_weather_text.setText(data.getTextDay());
            mf_weather_text_n.setText(data.getTextNight());
            mf_wind.setText(String.format("%s%s级\n风速:%skm/h", data.getWindDirDay(), data.getWindScaleDay(), data.getWindSpeedDay()));
            mf_tem.setText(String.format("%s~%s℃", data.getTempMin(), data.getTempMax()));
            mf2_wet.setText(String.format("%s%s", getString(R.string.wet), data.getHumidity()));
            mf2_down_water.setText(String.format("%s%s", getString(R.string.waterml), data.getPrecip()));
            mf2_air_press.setText(String.format("%s%s", getString(R.string.yaqiang), data.getPressure()));
            mf2_ziwaixian.setText(String.format("%s%s", getString(R.string.ziwaixian), data.getUvIndex()));
            mf2_can_see.setText(String.format("%s%s", getString(R.string.cansee), data.getVis()));
        }else{
            toast("未获取到天气预报数据");
        }
    }

    @Override
    public void initData() {

    }

    public static void setData(DailyWeatherAdapter.DailyBean data) {
        ShowForecastView.data = data;
    }

    public void finish(View view) {
        finish();
    }

    @Override
    protected void onDestroy() {
        ShowForecastView.data = null;
        super.onDestroy();
    }
}